package com.dingwei.superiordiary.ui.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperTextView;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.utils.DialogUtil;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.AppManager;
import com.lihao.baselibrary.utils.DataCleanManager;
import com.lihao.baselibrary.utils.IntentUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author 南柯一梦丶
 * Created time 2018/10/16.
 * Personal signature 余生还长 何必慌张
 * Page description :
 * .::::.
 * .::::::::.
 * :::::::::::
 * ..:::::::::::'
 * '::::::::::::'
 * .::::::::::
 * '::::::::::::::..
 * ..::::::::::::.
 * ``::::::::::::::::
 * ::::``:::::::::'        .:::.
 * ::::'   ':::::'       .::::::::.
 * .::::'      ::::     .:::::::'::::.
 * .:::'       :::::  .:::::::::' ':::::.
 * .::'        :::::.:::::::::'      ':::::.
 * .::'         ::::::::::::::'         ``::::.
 * ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 * '.:::::'                    ':'````..
 */
public class SetActivity extends BaseActivity {
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.notice)
    SuperTextView notice;
    @Bind(R.id.privacy)
    SuperTextView privacy;
    @Bind(R.id.other)
    SuperTextView other;
    @Bind(R.id.safe)
    SuperTextView safe;
    @Bind(R.id.mime)
    SuperTextView mime;
    @Bind(R.id.clear)
    SuperTextView clear;
    @Bind(R.id.exit)
    SuperTextView exit;
    @Bind(R.id.service)
    SuperTextView service;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_set;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tvTitle.setText("设置");
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.notice, R.id.privacy, R.id.other, R.id.safe, R.id.mime, R.id.clear, R.id.exit, R.id.service})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.notice:
                intent = new Intent(BaseActivity.context,NotifySetActivity.class);
                startActivity(intent);
                break;
            case R.id.privacy:
                intent = new Intent(BaseActivity.context,PrivacyActivity.class);
                startActivity(intent);
                break;
            case R.id.other:
                intent = new Intent(BaseActivity.context,OtherSetActivity.class);
                startActivity(intent);
                break;
            case R.id.safe:
                intent.setClass(BaseActivity.context,SafeSetActivity.class);
                startActivity(intent);
                break;
            case R.id.mime:
                intent.setClass(BaseActivity.context,PersonalDataActivity.class);
                startActivity(intent);
                break;
            case R.id.clear:
                DialogUtil.showAlertDialogChoose(BaseActivity.context, "温馨提醒", "是否确认清除" + clear.getRightString() + "缓存", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                            case DialogUtil.BUTTON1:
                                dialog.dismiss();
                                break;
                            case DialogUtil.BUTTON2:
                                dialog.dismiss();
                                DataCleanManager.clearAllCache(BaseActivity.context);
                                clear.setRightString("0.0K").useShape();
                                showToast("清理缓存成功");
                                break;
                        }
                    }
                });
                break;
            case R.id.exit:
                BaseActivity.value.setIsLogin(false);
                BaseActivity.value.setPhone("");
                BaseActivity.value.setUserId("");
                BaseActivity.value.setUserName("");
                BaseActivity.value.setToken("");
                BaseActivity.value.setJPush("");

                intent = new Intent(BaseActivity.context,LoginActivity.class);
                startActivity(intent);
                AppManager.getAppManager().finishActivity();
                break;
            case R.id.service:
//                intent = IntentUtils.getDialIntent("010-84909202");
//                startActivity(intent);
                intent = new Intent(BaseActivity.context,WebViewActivity.class);
                intent.putExtra("title","客服");
                intent.putExtra("url","http://www16.53kf.com/m.php?cid=72188509&arg=10188509&style=1");
                startActivity(intent);
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        try {
            clear.setRightString(DataCleanManager.getTotalCacheSize(BaseActivity.context)).useShape();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
